﻿// MIT License
//
// Copyright (c) 2021-present zuohuaijun, Daming Co.,Ltd and Contributors
//
// 电话/微信：18020030720 QQ群1：87333204 QQ群2：252381476

using Aliyun.Acs.Core.Exceptions;
using Aliyun.Acs.Core.Profile;
using Aliyun.Acs.Core;
using Aliyun.Acs.Dysmsapi.Model.V20170525;
using Furion.FriendlyException;
using Nest;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Admin.Net.InformationPlatform.Util
{ 
public class Sms
{
       /// <summary>
       /// 短信发送
       /// </summary>
       /// <param name="phoneNumber">手机号</param>
       /// <param name="TemplateCode">短信模板</param>
       /// <param name="name">变量值</param>
       /// <returns></returns>
        public static bool SendSms(string phoneNumber, string TemplateCode, string name)
        {
            IClientProfile profile = DefaultProfile.GetProfile("cn-hangzhou", "LTAI5tHfHb1stXD8u5qhCEXh", "7Z9GaSxeFFFV5HNx2dl82L1b2vNpPO");
            DefaultAcsClient client = new DefaultAcsClient(profile);
            SendSmsRequest request = new SendSmsRequest();
            request.PhoneNumbers = phoneNumber;

            request.SignName = "生久科技";// 短信签名，需要在阿里云控制台申请
            request.TemplateCode = TemplateCode; // 短信模板Code，需要在阿里云控制台申请(修改密码)
            request.TemplateParam = $"{{\"code\":\"123\"}}";
            request.TemplateParam = $"{{\"CustomName\":\"{name}\"}}";
            try
            {
                //发送短信
                SendSmsResponse response = client.GetAcsResponse(request);
                // 处理响应结果
                return true;
            }
            catch (ServerException ex)
            {
                throw Oops.Oh($"异常：{ex.Message}");
                // 处理异常
            }
        }
    }
}